home *** CD-ROM | disk | FTP | other *** search
- _STRUCTURED PROGRAMMING COLUMN_
- by Jeff Duntemann
-
-
- [LISTING ONE]
-
- {---------------------------------}
- { METHODS: TMortgageTopInterior }
- {---------------------------------}
-
- CONSTRUCTOR TMortgageTopInterior.Init(VAR Bounds : TRect);
-
- BEGIN
- TView.Init(Bounds); { Call ancestor's constructor }
- GrowMode := gfGrowHiX; { Permits pane to grow in X but not Y }
- END;
-
- PROCEDURE TMortgageTopInterior.Draw;
- VAR
- YRun : Integer;
- Color : Byte;
- B : TDrawBuffer;
- STemp : String[20];
- BEGIN
- Color := GetColor(1);
- MoveChar(B,' ',Color,Size.X); { Clear the buffer to spaces }
- MoveStr(B,' Principal Interest Periods',Color);
- WriteLine(0,0,Size.X,1,B);
-
- MoveChar(B,' ',Color,Size.X); { Clear the buffer to spaces }
- { Here we convert payment data to strings for display: }
- Str(Mortgage^.Principal:7:2,STemp);
- MoveStr(B[2],STemp,Color); { At beginning of buffer B }
- Str(Mortgage^.Interest*100:7:2,STemp);
- MoveStr(B[14],STemp,Color); { At position 14 of buffer B }
- Str(Mortgage^.Periods:4,STemp);
- MoveStr(B[27],STemp,Color); { At position 27 of buffer B }
- WriteLine(0,1,Size.X,1,B);
-
- MoveChar(B,' ',Color,Size.X); { Clear the buffer to spaces }
- MoveStr(B,
- ' Extra Principal Interest',
- Color);
- WriteLine(0,2,Size.X,1,B);
-
- MoveChar(B,' ',Color,Size.X); { Clear the buffer to spaces }
- MoveStr(B,
- 'Paymt # Prin. Int. Balance Principal So far So far ',
- Color);
- WriteLine(0,3,Size.X,1,B);
-
- END;
-
- {------------------------------------}
- { METHODS: TMortgageBottomInterior }
- {------------------------------------}
-
- CONSTRUCTOR TMortgageBottomInterior.Init(VAR Bounds : TRect;
- AHScrollBar, AVScrollBar : PScrollBar);
- BEGIN
- { Call ancestor's constructor: }
- TScroller.Init(Bounds,AHScrollBar,AVScrollBar);
- GrowMode := gfGrowHiX + gfGrowHiY;
- Options := Options OR ofFramed;
- END;
-
- PROCEDURE TMortgageBottomInterior.Draw;
- VAR
- Color : Byte;
- B : TDrawBuffer;
- YRun : Integer;
- STemp : String[20];
- BEGIN
- Color := GetColor(1);
- FOR YRun := 0 TO Size.Y-1 DO
- BEGIN
- MoveChar(B,' ',Color,80); { Clear the buffer to spaces }
- Str(Delta.Y+YRun+1:4,STemp);
- MoveStr(B,STemp+':',Color); { At beginning of buffer B }
- { Here we convert payment data to strings for display: }
- Str(Mortgage^.Payments^[Delta.Y+YRun+1].PayPrincipal:7:2,STemp);
- MoveStr(B[6],STemp,Color); { At beginning of buffer B }
- Str(Mortgage^.Payments^[Delta.Y+YRun+1].PayInterest:7:2,STemp);
- MoveStr(B[15],STemp,Color); { At position 15 of buffer B }
- Str(Mortgage^.Payments^[Delta.Y+YRun+1].Balance:10:2,STemp);
- MoveStr(B[24],STemp,Color); { At position 24 of buffer B }
- { There isn't an extra principal value for every payment, so }
- { display the value only if it is nonzero: }
- STemp := '';
- IF Mortgage^.Payments^[Delta.Y+YRun+1].ExtraPrincipal > 0
- THEN
- Str(Mortgage^.Payments^[Delta.Y+YRun+1].ExtraPrincipal:10:2,STemp);
- MoveStr(B[37],STemp,Color); { At position 37 of buffer B }
- Str(Mortgage^.Payments^[Delta.Y+YRun+1].PrincipalSoFar:10:2,STemp);
- MoveStr(B[50],STemp,Color); { At position 50 of buffer B }
- Str(Mortgage^.Payments^[Delta.Y+YRun+1].InterestSoFar:10:2,STemp);
- MoveStr(B[64],STemp,Color); { At position 64 of buffer B }
- { Here we write the line to the window, taking into account the }
- { state of the X scroll bar: }
- WriteLine(0,YRun,Size.X,1,B[Delta.X]);
- END;
- END;
-
- {------------------------------}
- { METHODS: TMortgageView }
- {------------------------------}
-
- CONSTRUCTOR TMortgageView.Init(VAR Bounds : TRect;
- ATitle : TTitleStr;
- ANumber : Integer;
- InitMortgageData :
- MortgageDialogData);
- VAR
- TopInterior : PMortgageTopInterior;
- BottomInterior : PMortgageBottomInterior;
- HScrollBar,VScrollBar : PScrollBar;
- R,S : TRect;
- BEGIN
- TWindow.Init(Bounds,ATitle,ANumber); { Call ancestor's constructor }
- { Call the Mortgage object's constructor using dialog data: }
- WITH InitMortgageData DO
- Mortgage.Init(PrincipalData,
- InterestData / 100,
- PeriodsData,
- 12);
- { Here we set up a window with *two* interiors, one scrollable, one }
- { static. It's all in the way that you define the bounds, mostly: }
- GetClipRect(Bounds); { Get bounds for interior of view }
- Bounds.Grow(-1,-1); { Shrink those bounds by 1 for both X & Y }
-
- { Define a rectangle to embrace the upper of the two interiors: }
- R.Assign(Bounds.A.X,Bounds.A.Y,Bounds.B.X,Bounds.A.Y+4);
- TopInterior := New(PMortgageTopInterior,Init(R));
- TopInterior^.Mortgage := @Mortgage;
- Insert(TopInterior);
-
- { Define a rectangle to embrace the lower of two interiors: }
- R.Assign(Bounds.A.X,Bounds.A.Y+5,Bounds.B.X,Bounds.B.Y);
-
- { Create scroll bars for both mouse & keyboard input: }
- VScrollBar := StandardScrollBar(sbVertical + sbHandleKeyboard);
- { We have to adjust vertical bar to fit bottom interior: }
- VScrollBar^.Origin.Y := R.A.Y; { Adjust top Y value }
- VScrollBar^.Size.Y := R.B.Y - R.A.Y; { Adjust size }
- { The horizontal scroll bar, on the other hand, is standard: }
- HScrollBar := StandardScrollBar(sbHorizontal + sbHandleKeyboard);
-
- { Create bottom interior object with scroll bars: }
- BottomInterior :=
- New(PMortgageBottomInterior,Init(R,HScrollBar,VScrollBar));
- { Make copy of pointer to mortgage object: }
- BottomInterior^.Mortgage := @Mortgage;
- { Set the limits for the scroll bars: }
- BottomInterior^.SetLimit(80,InitMortgageData.PeriodsData);
- { Insert the interior into the window: }
- Insert(BottomInterior);
- END;
-
-
-
-
- [LISTING TWO]
-
- PMortgageTopInterior = ^TMortgageTopInterior;
- TMortgageTopInterior =
- OBJECT(TView)
- Mortgage : PMortgage;
- CONSTRUCTOR Init(VAR Bounds : TRect);
- PROCEDURE Draw; VIRTUAL;
- END;
-
- PMortgageBottomInterior = ^TMortgageBottomInterior;
- TMortgageBottomInterior =
- OBJECT(TScroller)
- { Points to Mortgage object owned by TMortgageView }
- Mortgage : PMortgage;
- CONSTRUCTOR Init(VAR Bounds : TRect;
- AHScrollBar, AVScrollbar : PScrollBar);
- PROCEDURE Draw; VIRTUAL;
- END;
-
- PMortgageView = ^TMortgageView;
- TMortgageView =
- OBJECT(TWindow)
- Mortgage : TMortgage;
- CONSTRUCTOR Init(VAR Bounds : TRect;
- ATitle : TTitleStr;
- ANumber : Integer;
- InitMortgageData :
- MortgageDialogData);
- PROCEDURE HandleEvent(Var Event : TEvent); VIRTUAL;
- PROCEDURE ExtraPrincipal;
- PROCEDURE PrintSummary;
- DESTRUCTOR Done; VIRTUAL;
- END;
-
-